﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LevenBlog.Core.Entities;
using LevenBlog.Core.User;

namespace LevenBlog.Core.WebService.Entities
{
    [Serializable]
    public class Role
    {
        public int ID { get; set; }

        public string Name { get; set; }

        public string Intro { get; set; }

        public string Code { get; set; }

        public Authority authority { get; set; }

        public Role()
        {
        }

        public virtual void FillWithDbEntity(lb_usertype type)
        {
            ID = type.id;
            Name = type.name;
            Intro = type.intro;
            Code = type.competence;
            authority=new Authority();
            authority.Fill(type.competence);
        }

        public void ConvertCodeToAuthorty()
        {
            if (authority == null)
                authority = new Authority();
            authority.Fill(Code);
        }

        public void ConvertAuthortyToCode()
        {
            if (authority == null)
                throw new ArgumentNullException("authortity");
            Code = authority.ToCode();
        }

        public lb_usertype ToEntity()
        {
            lb_usertype type = new lb_usertype();
            type.id = ID;
            type.intro = Intro;
            type.name = Name;
            type.competence = Code;
            return type;
        }
    }
}
